# -*- coding: utf-8 -*-
# Project : flacon
# File : ogg_encoder.py
# (c) Alexander Sokolov sokoloff.a@gmail.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.



import encoder
import errors
from settings import *
from flaconglobal import *
from PyQt4 import QtCore
import sys, re

import aac_config

class AacEncoder(encoder.Encoder):
    id = 'AAC'
    extension = 'm4a'
    name = 'AAC'

   #****************************************************************
   #
   #****************************************************************
    @classmethod
    def trackGainClass(cls):
        return None


   #****************************************************************
   #
   #****************************************************************
    @classmethod
    def configPageClass(cls):
        return aac_config.AacConfig


   #****************************************************************
   #
   #****************************************************************
    @classmethod
    def programs(cls):
        return ['faac']


   #****************************************************************
   #
   #****************************************************************
    def getEncoderArgs(self):
        args = QStringList()
        args << settings.value("Programs/faac").toString()
        args << "-w" # Wrap  AAC  data  in  an MP4 container.

        # Quality settings .........................................
        if settings.value("Aac/UseQuality").toBool():
            args << "-q" << settings.value("Aac/Quality").toString()
        else:
            args << "-b" << settings.value("Aac/Bitrate").toString()

        # Tags .....................................................
        # --artist artist
        #     Set artist to artist
        if (self._track.artist()):  args << "--artist"  << self._track.artist()

        # --writer writer
        #     Set writer to writer

        # --title title
        #     Set title to title
        if (self._track.title()):   args << "--title"   << self._track.title()

        # --genre genre
        #     Set genre to genre
        if (self._track.genre()):   args << "--genre"   << self._track.genre()

        # --album album
        #     Set album to album
        if (self._track.album()):   args << "--album"   << self._track.album()

        # --compilation
        #     Set compilation

        # --track track
        #     Set track to track in the format “number/total”
        args << "--track" << QString("%1/%2").arg(self._track.trackNum()).arg(self._track.trackSet().count())

        # --disc disc
        #     Set disc to disc in the format “number/total”

        # --year year
        #     Set year to year
        if (self._track.year()):    args << "--year"    << str(self._track.year())

        # --cover-art file
        #     Set cover art to image in file; supported formats are GIF, JPEG, and PNG.

        # --comment comment
        #     Set comment to comment
        if (self._track.comment()): args << "--comment" << self._track.comment()


        # Files ....................................................
        args << "-o" << self._outFile
        args << "-"
        return args



#****************************************************************
# Register encoder & gain classes
#****************************************************************
encoder.registerEncoder(AacEncoder)
